package com.model.defaults.tabsheet;

import java.util.Map;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.core.hibernate.ExceptionHandler;
import com.core.hibernate.exceptionevent.ExceptionEvent;
import com.model.UserContextName;
import com.model.defaults.tabsheet.entities.ModelDefaultTabsheetAdministration;
import com.model.defaults.tabsheet.entities.ModelDefaultTabsheetProject;
import com.model.defaults.tabsheet.entities.ModelDefaultTabsheetReport;
import com.model.defaults.tabsheet.entities.ModelDefaultTabsheetRole;
import com.model.defaults.tabsheet.entities.ModelDefaultTabsheetTask;
import com.model.defaults.tabsheet.entities.ModelDefaultTabsheetTeam;
import com.model.defaults.tabsheet.entities.ModelDefaultTabsheetUser;
import com.model.defaults.tabsheet.entities.ModelDefaultTabsheetVersion;

public class ModelDefaultTabsheetItems {



	public static void createTabsheetItems ( Session session,
	                                         Map <String, UserContextName> userContexts ) {

		Transaction transaction = null;

		try {

			transaction = session.beginTransaction();



			ModelDefaultTabsheetProject.createTabsheetItemsProject(session, userContexts);
			ModelDefaultTabsheetTask.createTabsheetItemsTaskOpen(session, userContexts);
			ModelDefaultTabsheetAdministration.createTabsheetItemsAdministration(session, userContexts);
			ModelDefaultTabsheetUser.createTabsheetItemsUserOpen(session, userContexts);
			ModelDefaultTabsheetVersion.createTabsheetItemsVersionInfo(session, userContexts);
			ModelDefaultTabsheetRole.createTabsheetItemsRoleInfo(session, userContexts);
			ModelDefaultTabsheetReport.createTabsheetItemsReportInfo(session, userContexts);
			ModelDefaultTabsheetTeam.createTabsheetItemsTeamInfo(session, userContexts);

			transaction.commit();

		} catch ( RuntimeException runtimeException ) {
			ExceptionHandler.handleException(runtimeException, new ExceptionEvent(ExceptionEvent.TABSHEETS));
			if ( transaction != null ) {
				if ( transaction.isActive() ) {
					try {
						transaction.rollback();
					} catch ( HibernateException hibernateException ) {
						ExceptionHandler.handleException(hibernateException, new ExceptionEvent(ExceptionEvent.TABSHEETS));
					}
				}
			}
		}

	}
}
